/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package xmlutils;

import DAO.ArtistDAO;
import DAO.SongDAO;
import DTO.artist.Artists;
import DTO.song.Songs;

/**
 *
 * @author NoiR
 */
public class XMLUnmarshaller {
    // ThuanNH

    private final String buildDir = "/build/web/xml/";
    private final String webDir = "/web/xml/";
    // ThuanNH

    public void UnmarshalSongXML() {
        String xml = "Songs.xml";
        String xsd = "song.xsd";

        Songs songs = (Songs) XMLUtils.unmarshallXML(xsd, buildDir + xml);
        if (songs != null) {
            SongDAO dao = new SongDAO();
            dao.saveAllToDatabase(songs);

            System.out.println("Saved!!!");
        } else {
            System.out.println("Can not save!!");
        }
    }

    // TanND
    public void UnmarshalArtistXML() {
        String xml = "Artist.xml";
        String xsd = "artist.xsd";

        Artists artists = (Artists) XMLUtils.unmarshallXML(xsd, buildDir + xml);
        if (artists != null) {
            ArtistDAO artistDAO = new ArtistDAO();
            artistDAO.saveAll(artists);
            
            System.out.println("Saved!!!");
        } else {
            System.out.println("Can not save!!");
        }
    }
}
